package com.ella.exceptionhandler;
import com.ella.common.security.exception.TokenException;
import com.ella.common.security.exception.UserCountLockException;
import com.ella.common.security.exception.UserLoginLimitException;
import com.ella.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 只有用户抛出的异常才能捕获
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    //用户登录异常捕获
    @ExceptionHandler(value = UserLoginLimitException.class)
    public Result handler(UserLoginLimitException e){
        log.error("用户登录异常捕获：---------{}"+e.getMessage());
        return Result.error(e.getMessage());
    }
    /*@ExceptionHandler(value = UserCountLockException.class)
    public Result UserCountLock(UserCountLockException userLoginException){
        log.error("该用户账号被封禁，具体请联系管理员---------{}"+userLoginException.getMessage());
        return Result.error(userLoginException.getMessage());
    }*/

    @ExceptionHandler(value = RuntimeException.class)
    public Result RuntimeHandler(RuntimeException e){
        log.error("用户登录异常捕获：---------{}"+e.getMessage());
        return Result.error(e.getMessage());
    }


    @ExceptionHandler(value = AccessDeniedException.class)
    public Result AccessDenied(AccessDeniedException runtimeException){
        log.error("权限校验异常---------{}"+runtimeException.getMessage());
        return Result.error(runtimeException.getMessage());
    }


    @ExceptionHandler(value = TokenException.class)
    public Result AccessDenied(TokenException tokenException){
        log.error("权限校验异常---------{}"+tokenException.getMessage());
        return Result.error(tokenException.getMessage());
    }




}
